const util = require("../../utils/util")
const domainName = getApp().globalData.domainName
const oss_domain = getApp().globalData.oss_domain
const parameter = getApp().globalData.parameter
const video_list = [
  {url:'https://yqwl.top/static/video/app_videos/exam_fly.mp4'},
  {url:'https://yqwl.top/static/video/app_videos/gs_index.mp4'},
  {url:'https://yqwl.top/static/video/app_videos/simulate_fly_8.mp4'},
]

const banner_list = [
  {pic_url:'https://yqwl.top/static/picture/banner_pic/banner3.jpg'},
  {pic_url:'https://yqwl.top/static/picture/banner_pic/banner2.png'},
  {pic_url:'https://yqwl.top/static/picture/banner_pic/banner1.png'},
]
// 更新本地题库，并返回本地题库
const update_local_tiku=(new_ti_list, local_tiku)=>{
  var local_tiku = local_tiku || []
  // 将修改的题，在原题基础上更新
  for(var i=0; i<new_ti_list.length; i++){
    var not_exist = true
    for(var j=0; j<local_tiku.length; j++){
      if(new_ti_list[i].ti_id == local_tiku[j].ti_id){
        local_tiku[j] = new_ti_list[i]
        var not_exist = false
        break
      }
    }
    if(not_exist){  // 若不存在，则添加
      local_tiku.push(new_ti_list[i])
    }
  }
  return local_tiku
}
const page_init=(that,user_id)=>{
  // 如果有user_id，那么请求该用户相关的数据，否则先获取该用户的user_di，然后再请求该用户相关的数据
  wx.request({
    url: domainName + '/index_page_init',
    data: {
      user_id:user_id,
    },...parameter,
    success: res => {
      let res_data = res.data
      console.log('res_data',res_data)
      let jg_stu_id = res_data.jg_stu_id
      wx.setStorageSync('jg_stu_id', jg_stu_id)
      that.jg_stu_id = jg_stu_id
      that.jg_id_of_stu = res_data.jg_id_of_stu
      that.setData({
        jg_stu_id,
        chap_list:res_data.chap_list,
        phone:res_data.phone || '',
        jg_list:res_data.jg_list,
        jg_name_of_stu:res_data.jg_name_of_stu,
        jg_logo_of_stu:res.data.jg_logo_of_stu,
        avatar:res_data.avatar,
        banner_list:res_data.banner_list ||  banner_list,
        show_video:res_data.show_video,
        show_mall:res_data.show_mall,
        show_recruitment:res_data.show_recruitment,
        loading:false,  // 隐藏 骨架屏
      })
      wx.hideLoading()
    },
  })
}
const get_openid_userid=(that,js_code)=>{
  // 发送 res.code 到后台换取 openId, sessionKey, unionId
  wx.request({
    url: domainName + '/get_openid_userid',
    data: {
      js_code:js_code
    },...parameter,
    success: res => {
      let user_id = res.data.user_id
      wx.setStorageSync('user_id', user_id)
      page_init(that,user_id)
    },
    fail:err=>{
      getApp().timeout_reconnect(err.errMsg,that)
    }
  })
}
// 将每一节最近更新的时间列表返回服务器，对比是否需要更新，并且返回新题列表
const if_need_update_tiku=(that, sec_last_update_time_list, chap_info)=>{
  // 检查是否需要更新
  wx.request({
    url: domainName + '/if_need_update_tiku',
    data: {
      sec_last_update_time_list:JSON.stringify(sec_last_update_time_list),
    },...parameter,
    success: res => {
      // console.log('res', res.data)
      let lis = res.data.lis

      if(lis.length>0){
        // 延时一秒更新本地题库
        setTimeout(() => {wx.hideLoading()}, 1000);
        wx.showModal({
          cancelText:'稍后',
          confirmText:'立即更新',
          content: '发现有新题，是否立即更新？',
          showCancel: true,
          title: '提示',
          success: res => {
            if(res.confirm){
              for(var h=0; h<lis.length; h++){
                // 将新题 加入 本地题库
                let sec_id = lis[h].sec_id
                let local_tis = wx.getStorageSync('local_tis' + sec_id)
                that.local_tis = update_local_tiku(lis[h].new_ti_list, local_tis) // 对比新题
                wx.setStorageSync('local_tis' + sec_id, that.local_tis)

                // 更新本地，本章节最近更新习题时间
                wx.setStorageSync('sec_update' + sec_id, util.formatTime(new Date()))
              }
              wx.showModal({
                content: '更新完成！',
                showCancel: false,
                title: '提示',
              })
            }
          },
        })
      }else{
        // 延时一秒前往本章页面
        setTimeout(() => {
          wx.navigateTo({
            url: '/pages/doTi/exercise_book/exercise_book?chap_info=' + encodeURIComponent(JSON.stringify(chap_info))
          })
        }, 1000);
      }
    },
  })
}
// // 检查习题是否更新
// const check_tiku_update=(chap_id)=>{
//     wx.showLoading({
//       title: '检查中...',
//     })
//     let the_key = 'chap_update' + chap_id
//     let chap_last_update_time = wx.getStorageSync(the_key)
//     wx.request({
//       url: domainName + 'check_has_tiku_update',
//       data: {
//         chap_id:chap_id,
//         chap_last_update_time:chap_last_update_time,
//         // ti_ku:JSON.stringify(local_tiku || [])
//       },...parameter,
//       success: res => {
//         wx.hideLoading()
//         let new_ti_list = res.data.new_ti_list
//         // console.log('new_ti_list', new_ti_list.length, new_ti_list)
//         if(new_ti_list.length>0){
//           wx.showModal({
//             cancelText:'稍后',
//             confirmText:'立即更新',
//             content: '发现有新题，是否立即更新？',
//             showCancel: true,
//             title: '提示',
//             success: res => {
//               if(res.confirm){

//                 // 将新题 加入 本地题库
//                 let local_tiku = wx.getStorageSync('local_tiku' + chap_id)
//                 that.local_tiku = update_local_tiku(new_ti_list, local_tiku)
//                 wx.setStorageSync('local_tiku' + chap_id, that.local_tiku)
                
//                 // 更新本地，本章节最近更新习题时间
//                 wx.setStorageSync(the_key, util.formatTime(new Date()))
//                 wx.showModal({
//                   cancelText: '忽略',
//                   confirmText: '查看更新',
//                   content: '更新完成！',
//                   showCancel: true,
//                   title: '提示',
//                   success: res => {
//                     if(res.confirm){
//                       // 获取新题列表，前往做题页面
                                
//                       let url_data = 
//                       'do_what=new_tis' + 
//                       '&chap_id=' + chap_id + 
//                       '&jg_id=' + (that.jg_id_of_stu || that.jg_id_of_admin) + 
//                       '&jg_stu_id=' + that.jg_stu_id +
//                       '&tis=' + encodeURIComponent(JSON.stringify(new_ti_list || []))

//                       getApp().get_vibration()
                      
//                       wx.navigateTo({
//                         url: '/pages/do_ti_new/do_ti_new?' + url_data,
//                       })

//                     }
//                   },
//                 })
//               }
//             },
//           })
//         }else{
//           wx.showToast({
//             title: '已是最新！',
//             duration: 2000,
//             icon: 'success',
//             mask: false,
//           })
//         }
//       },
//     })

//   }
  // 更新做题数据
const index_reload_doti_info=(that, jg_stu_id)=>{
    wx.showLoading()
    wx.request({
      url: domainName + '/index_reload_doti_info',
      data: {
        jg_stu_id:jg_stu_id || '',
      },...parameter,
      success: res => {
        wx.hideLoading()
        that.setData({
          chap_list:res.data.chap_list,
        })
      },
      fail:err=>{
        getApp().timeout_reconnect(err.errMsg,that)
      }
    })
  }
const user_id = wx.getStorageSync('user_id')

Page({

  /**
   * 页面的初始数据
   */
  data: {
    video_list,
    icon_url:oss_domain + 'static/picture/app_icon/',
    menuButtonObject : wx.getMenuButtonBoundingClientRect(),
    windowWidth : wx.getSystemInfoSync().windowWidth,
    loading:false,
    current:0,
    muted:wx.getStorageSync('muted') ,
    defalut_avatar:'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',


    new_ti_list:[],


    chap_list : [
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_1.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_2.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_3.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_4.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_5.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_6.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_7.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_8.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_17.png'},
      {picture:'https://yqwl.top/static/picture/chap_pic/chap_9.png'},
    ],
    


  },

  // 前往训练指引
  howToStart(){
    wx.showToast({
      title: '开发中……',
      duration: 1000,
      icon: 'none',
    })
    
  },

  // 前往综合问答
  qa(){
    let chap_info = this.data.chap_list[8]
    this.check_tiku_update_section(chap_info)
  },

  // 前往章节页面
  tap_chap(e){
    getApp().get_vibration()
    let index = e.currentTarget.id
    let chap_info = this.data.chap_list[index]
    // wx.navigateTo({
    //   url: '/pages/doTi/exercise_book/exercise_book?chap_info=' + encodeURIComponent(JSON.stringify(chap_info))
    // })
    this.check_tiku_update_section(chap_info)
  },

  // 检查该章中所有的节是否需要更新
 check_tiku_update_section(chap_info){
  // 1.本地获取该【章】中所有【节】的更新到本地的最近时间，并生成列表【sec_last_update_time_list】
  // 2.将带有更新时间的【节】列表传回服务器，对比时间是否一致？如果早于服务器的时间，那么就需要更新


    wx.showLoading({title: '连接标准题库...'})
    // 获取每一节的最近更新时间
    var sec_id_list = chap_info.sec_id_list
    var sec_last_update_time_list = []
    for(var k=0; k<sec_id_list.length; k++){
      let sec_id = sec_id_list[k]
      let the_key = 'sec_update' + sec_id
      let sec_last_update_time = wx.getStorageSync(the_key)
      let dic = {
        'sec_id':sec_id,
        'sec_last_update_time':sec_last_update_time,
      }
      sec_last_update_time_list.push(dic) // 每一节的最近更新时间列表
    }
    // 将更新时间打包，发回服务器对比
    if_need_update_tiku(this, sec_last_update_time_list, chap_info)
  },
  // 预测考分
  predict_score(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/students/predict_ExamScore/predict_ExamScore?jg_stu_id=' + this.jg_stu_id,
    })
  },
  // 地面站
  gs(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/gs/dji/dji?show_video=' + this.data.show_video,
  })},
  // 飞行
  fly(){
    getApp().get_vibration()
    wx.navigateToMiniProgram({
      appId: 'wxafc64a6b71377df9',
      path: 'pages/dzz/index',
      extraData: {
      },    // 目标小程序可在 App.onLaunch 或 App.onShow 中接收该数据
      envVersion: 'release',
      success(res) {
        // 打开成功
      }
    })
    // wx.showToast({
    //   title: '开发中……',
    //   icon:'none'
    // })
  },
  show_exam_sites(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/exam_sites/exam_sites',
    })
  },
  view_jg(e){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/jg_page/jg_page?jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin),
    })
  },
  // 前往资料库
  view_library(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/information/text_list/text_list'
    })
  
  },
  // 前往享飞公共平台
  go_xfjf(){
    getApp().get_vibration()
    wx.navigateToMiniProgram({
      appId: 'wxce49f6a3d4368c8b',
    })
  },
  // 前往查看飞行记录本
  flight_logs(e){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/flight_logs/flight_logs?jg_stu_id=' + this.jg_stu_id,
    })
  },
  // 我的证件首页
  my_paper_index(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_paper_index/my_paper_index?user_id=' + user_id,
    })
  },
  // 静音
  muted(){
    getApp().get_vibration()
    let muted = !this.data.muted
    this.setData({
      muted:muted,
    })
    wx.setStorageSync('muted', muted)
  },
  // 切换swiper
  swiper_change(e){
    // console.log('切换swiper',e.detail)
    if(e.detail.source == 'touch'){
      let current = e.detail.current
      for(var i=0; i<this.data.video_list.length; i++){
        let videoContext_other = wx.createVideoContext('video_' + i)
        videoContext_other.pause()
      }

      let videoContext = wx.createVideoContext('video_' + current)
      videoContext.play()

      this.setData({
        current:current,
      })
    }
  },
  // 视频播放完毕后
  video_end(){
    if(this.data.current==this.data.video_list.length-1){
      var current = 0
    }else{
      var current = this.data.current + 1
    }
    this.setData({
      current:current
    })
  },
  // 练习今日全国易错99题
  do_error_prone_today(){
    wx.showActionSheet({
      itemList: ['看一看','练一练'],
      success: res => {
        getApp().get_vibration()
        var tapIndex = res.tapIndex
        wx.showLoading({title: '连接标准题库……'})
        wx.request({
          url: domainName + '/do_error_prone_today',
          data: {},...parameter,
          success: res => {
            wx.hideLoading()
            let tis = getApp().random_optList_of_tiku(res.data.tis) //随机乱序题库选项
            // console.log('tis',tis)
            if(tis.length>0){
              if(tapIndex==0){
                var url = '/pages/doTi/read_tis/read_tis?tis=' + encodeURIComponent(JSON.stringify(tis || [])) + '&page_title=今日全国易错99题'
              }else if(tapIndex==1){
                  var url = '/pages/doTi/do_ti/do_ti?tis=' + encodeURIComponent(JSON.stringify(tis || [])) + '&page_title=今日全国易错99题'
              }
              wx.navigateTo({
                url: url,
              })
            }else{
              wx.showToast({
                title: '今日还没有习题',
                duration: 1500,
                icon: 'error',
              })
            }
          },
          fail:err=>{
            getApp().timeout_reconnect(err.errMsg,this)
          }
        })

      },
    })

  },
  // 练习全国高频错题99
  do_error_prone(){
    wx.showActionSheet({
      itemList: ['看一看','练一练'],
      success: res => {
        getApp().get_vibration()
        var tapIndex = res.tapIndex
        wx.showLoading({title: '连接标准题库……'})
        wx.request({
          url: domainName + '/query_error_prone',
          data: {},...parameter,
          success: res => {
            wx.hideLoading()
            let tis = getApp().random_optList_of_tiku(res.data.tis) //随机乱序题库选项
            if(tis.length>0){
              if(tapIndex==0){
                var url = '/pages/doTi/read_tis/read_tis?tis=' + encodeURIComponent(JSON.stringify(tis || [])) + '&page_title=累计全国易错99题'
              }else if(tapIndex==1){
                  var url = '/pages/doTi/do_ti/do_ti?tis=' + encodeURIComponent(JSON.stringify(tis || [])) + '&page_title=累计全国易错99题'
              }
              wx.navigateTo({
                url: url,
              })
            }else{
              wx.showToast({
                title: '这里没有习题',
                duration: 1500,
                icon: 'error',
              })
            }
          },
          fail:err=>{
            getApp().timeout_reconnect(err.errMsg,this)
          }
        })

      },
    })

  },

  // 我发布的习题
  my_Questions(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_question_bank/my_question_bank',
    })
  },

  // 前往学员主页(实训记录)
  stu_homepage(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/stu_homepage_of_yqwl/stu_homepage_of_yqwl?jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + '&stu_id=' + user_id + '&jg_stu_id=' + this.jg_stu_id,
    })
  },

  // 前往地图页面
  map_jg(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/map_jg/map_jg',
    })
  },


  // 我的学员管理
  tap_students(){
    getApp().get_vibration()
    let jg_list = this.data.jg_list
    if(jg_list.length>1){
      wx.showActionSheet({
        itemList: jg_list.map(x=>x.jg_name),
        success: res => {
          wx.navigateTo({
            url: '/pages/students/index/index?jg_id=' + jg_list[res.tapIndex].jg_id + '&jg_name=' + jg_list[res.tapIndex].jg_name,
          })
        },
      })
    }else{
      getApp().get_vibration()
      wx.navigateTo({
        url: '/pages/students/index/index?jg_id=' + jg_list[0].jg_id + '&jg_name=' + jg_list[0].jg_name,
      })
    }
  },



  // 查看权限界面
  view_right_count(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_use_right/my_use_right?user_id=' + user_id,
    })
  },

  // 前往个人中心
  personal(e){
    getApp().get_vibration()
    if(this.data.phone.length==11){
      var url = '/pages/users/personal/personal'
    }else{
      var url = '/pages/users/login/login'
    }
    wx.navigateTo({
      url:url,
    })
  },




  // 前往找工作
  recruitment_list(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/recruitment/recruitment_list/recruitment_list',
    })
  },

  // 自定义考试
  do_test(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/doTi/custom_testPapers/custom_testPapers?jg_stu_id=' + this.jg_stu_id
    })
  },

  // 学习相关
  learning_index(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/learning_index/learning_index',
    })
  },

  // 教学视频
  edu_video(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/teaching_video/teaching_video',
    })
  },

  // 训练记录
  train_log_create(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/train_log_list/train_log_list?jg_stu_id=' + this.jg_stu_id + '&stu_name=我'
    })
  },

  // 搜索习题
  search_ti(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/doTi/search_ti/search_ti'
    })
  },

  // 去考试
  my_test_paper(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/my_test_paper/my_test_paper',
    })
  },


  a(){
    wx.showLoading({
      title: '检查中...',
    })
  },




  // 加载错题库
  load_wrong_ti_list(stu_id){
    wx.showLoading()
    wx.request({
      url: domainName + '/load_wrong_ti_list',
      data: {
        stu_id:stu_id,
      },...parameter,
      success: res => {
        wx.hideLoading()
        // console.log('res.data',res.data)
        let ti_list = res.data.ti_list
        let url_data = 
        'do_what=do_wrongs' + 
        '&chap_id=' + '' + 
        '&jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + 
        '&jg_stu_id=' + this.jg_stu_id +
        '&tis=' + encodeURIComponent(JSON.stringify(ti_list || []))

        console.log('用的本地题库')

        wx.navigateTo({
          url: '/pages/do_ti_new/do_ti_new?' + url_data,
        })
      },
    })
  },


  // 加载错题库
  load_bookmark_ti_list(stu_id){
    wx.showLoading()
    wx.request({
      url: domainName + '/load_bookmark_ti_list',
      data: {
        stu_id:stu_id,
      },...parameter,
      success: res => {
        wx.hideLoading()
        // console.log('res.data',res.data)
        let ti_list = res.data.ti_list
        let url_data = 
        'do_what=do_bookmark' + 
        '&chap_id=' + '' + 
        '&jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + 
        '&jg_stu_id=' + this.jg_stu_id +
        '&tis=' + encodeURIComponent(JSON.stringify(ti_list || []))

        console.log('用的本地题库')

        wx.navigateTo({
          url: '/pages/do_ti_new/do_ti_new?' + url_data,
        })
      },
    })
  },


  // 加载错题库
  load_bookmark_tiID_list(stu_id, chap_id){
    wx.showLoading()
    wx.request({
      url: domainName + '/load_bookmark_tiID_list',
      data: {
        stu_id:stu_id,
        chap_id:chap_id,
      },...parameter,
      success: res => {
        wx.hideLoading()
        console.log('res.data',res.data)
        let ti_id_list = res.data.ti_id_list
        let ti_list = []
        for(var i=0; i<this.local_tiku.length; i++){
          if(ti_id_list.indexOf(this.local_tiku[i].ti_id)>-1){
            ti_list.push(this.local_tiku[i])
          }
        }

        let url_data = 
        'do_what=do_bookmark' + 
        '&chap_id=' + '' + 
        '&jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + 
        '&jg_stu_id=' + this.jg_stu_id +
        '&tis=' + encodeURIComponent(JSON.stringify(ti_list || []))

        console.log('用的本地题库')

        wx.navigateTo({
          url: '/pages/do_ti_new/do_ti_new?' + url_data,
        })
      },
    })
  },

  // 开始做题（错题库、收藏夹）
  do_ti(e){
    getApp().get_vibration()
    var do_what = e.currentTarget.dataset.do_what
    if(do_what=='do_wrongs'){
      if(this.data.wrongs_count>100){
        wx.showModal({
          confirmText:'开始做题',
          content: '每次最多只能随机100题',
          showCancel: true,
          title: '提示',
          success: res => {
            if(res.confirm){
              this.load_wrong_ti_list(user_id)
            }
          },
        })
      }else if(this.data.wrongs_count>0){
        this.load_wrong_ti_list(user_id)
      }else{
        wx.showToast({
          title: '这里没有习题',
          duration: 1500,
          icon: 'error',
        })
      }
    }else if(do_what=='do_bookmark'){
      if(this.data.bookmarks_count>0){
        this.load_bookmark_ti_list(user_id)
      }else{
        wx.showToast({
          title: '这里没有习题',
          duration: 1500,
          icon: 'error',
        })
      }
    }
  },



  // 加载习题ID列表
  // load_ti_id_list(jg_stu_id,jg_id,stu_id,do_what,chap_id,local_tiku){
  //   wx.request({
  //     url: domainName + '/load_ti_id_list',
  //     data: {
  //       jg_stu_id:jg_stu_id,
  //       jg_id:jg_id,
  //       stu_id:stu_id,
  //       do_what:do_what,
  //       chap_id:chap_id,
  //     },...parameter,
  //     success: res => {

  //       let ti_id_list = res.data.ti_id_list
  //       // console.log('ti_id_list',ti_id_list)
  //       // 根据习题ID列表，获取习题列表
  //       var ti_list = []
  //       for(var i=0; i<local_tiku.length; i++){
  //         if(ti_id_list.indexOf(local_tiku[i].ti_id) > -1){
  //           ti_list.push(local_tiku[i])
  //         }
  //       }
  //       if(ti_list.length==0){
  //         wx.showModal({
  //           cancelText: '取消',
  //           confirmText: '立即检查',
  //           content: '请先“检查更新题库”',
  //           showCancel: true,
  //           title: '提示',
  //           success: res => {
  //             if(res.confirm){
  //               check_tiku_update(chap_id)
  //             }
  //           },
  //         })
  //         return
  //       }
  //       let url_data = 
  //       'do_what=' + do_what + 
  //       '&chap_id=' + chap_id + 
  //       '&jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + 
  //       '&jg_stu_id=' + this.jg_stu_id +
  //       '&tis=' + encodeURIComponent(JSON.stringify(ti_list || []))

  //       console.log('用的本地题库')

  //       wx.navigateTo({
  //         url: '/pages/do_ti_new/do_ti_new?' + url_data,
  //       })


  //       // console.log('ti_id_list',ti_id_list)
  //       // if(ti_id_list.length>0){
  //       //   let url_data = 
  //       //     'ti_id_list=' + JSON.stringify(ti_id_list || []) + 
  //       //     '&do_what=' + do_what + 
  //       //     '&chap_id=' + chap_id + 
  //       //     '&jg_id=' + (this.jg_id_of_stu || this.jg_id_of_admin) + 
  //       //     '&jg_stu_id=' + this.jg_stu_id
  //       //   wx.navigateTo({
  //       //     url: '/pages/do_ti/do_ti?' + url_data
  //       //   })
  //       // }else{
  //       //   wx.showToast({
  //       //     title: '这里没有习题',
  //       //     duration: 1500,
  //       //     icon: 'error',
  //       //   })
  //       // }
  //     },
  //     fail:err=>{
  //       getApp().timeout_reconnect(err.errMsg,this)
  //     }
  //   })
  // },


  // 查看群英排行榜
  rank_test_index(){
    getApp().get_vibration()
    wx.navigateTo({
      url:'/pages/students/rank_test_index/rank_test_index'
    })
  },

  // 查看最糗排行榜
  rank_wrong_index(){
    getApp().get_vibration()
    wx.navigateTo({
      url:'/pages/students/rank_wrong_index/rank_wrong_index'
    })
  },

  // 查看靓仔排行榜
  rank_mine_index(){
    getApp().get_vibration()
    wx.navigateTo({
      url:'/pages/students/rank_mine_index/rank_mine_index?jg_stu_id=' + this.jg_stu_id
    })
  },

  // 创建动画
  create_animation(){
    this.animation = wx.createAnimation()
    this.animation.translateX(-65).step({ duration: 400 })
    setTimeout(() => {
      this.setData({
        animationData: this.animation.export()
      })
    }, 1000);
  },

  //点评今日飞行训练
  // 填写飞行记录本
  create_flight_log(){
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/stu_list_of_ins/stu_list_of_ins'
    })
  },

  // 学员页面
  im_stu(){
    // console.log('学员页面')
    getApp().get_vibration()
    wx.navigateTo({
      url: '/pages/students/my_trainings/my_trainings?jg_stu_id=' + this.jg_stu_id + '&jg_id=' + this.jg_id_of_stu,
    })
  },

  

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showLoading() 
    
    // 创建动画
    this.create_animation()

    // 自动播放第一个视频
    let videoContext = wx.createVideoContext('video_0')
    videoContext.play()

    if(user_id){
      page_init(this,user_id)
    }else{
      wx.login({
        // timeout: 0,
        success: res => {
          // console.log('用户登录',res)
          let js_code = res.code
          get_openid_userid(this,js_code)
        },
      })
    }

  },

  onHide(){
    this.can_onshow = true
  },

  onShow(){
    if(this.can_onshow){
      page_init(this,user_id)
    }
  },

  onReady(){
    this.setData({
      windowHeight:wx.getSystemInfoSync().windowHeight
    })
  },

  // 下拉刷新
  onPullDownRefresh(){
    console.log('下拉刷新')
    this.onLoad()
    index_reload_doti_info(this, user_id, (this.jg_id_of_stu || this.jg_id_of_admin), this.jg_stu_id)
    wx.stopPullDownRefresh()
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function (e) {

  }
})